const {wait} = require('zcutil-cli-input')

//@SpringBoot
class Application {

	//@Autowired
	yqOkexApiService;

	log;

	//查询价格
	async testSearchPrice(){

		const coin = "BTC-USDT"

		const log = this.log.method("testSearchPrice")

		log.info(`请求价格:${coin}`);

		const price = await this.yqOkexApiService.getTicker(coin)

		log.info(`${coin}:${price}`)
	}


	//查询余额
	async testBalance(coinName){
		const log = this.log.method("testBalance")
		log.info(`开始查询${coinName}余额`)
		const balance = await this.yqOkexApiService.getBalance(coinName)
		log.info(`${coinName}:${balance}`)
	}

	//测试购买4U usdt
	async testBuyBTC(){
		const log = this.log.method("testBuyBTC")
		log.info(`测试购买3U  BTC`)
		const result = await this.yqOkexApiService.buy('BTC-USDT',3)
		log.info(`服务器返回:${JSON.stringify(result)}`)
	}

	async testSell(size){
		const log = this.log.method("testSell")
		log.info(`出售BTC 数量:${size}`)
		const result = await this.yqOkexApiService.sell('BTC-USDT',size)
		log.info(`服务器返回:${JSON.stringify(result)}`)
	}

	async main(){

		const panic = await this.yqOkexApiService.getMarketSentiment();

		this.log.info(`恐慌情绪:${panic}`)

		//查询价格
		await this.testSearchPrice();

		//查询余额
		await this.testBalance("BTC");

		//测试购买
		await this.testBuyBTC();

		this.log.info("等待2秒！")
		await wait(2)

		//重新查询余额
		await this.testBalance("BTC");

		//测试出售
		await this.testSell(0.0001)

		this.log.info("等待2秒！")
		await wait(2)

		//重新查询余额
		await this.testBalance("BTC");

	}

}

 module.exports = { Application }